﻿using Eneta.Profiles.Models;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement;

namespace Eneta.Profiles.Drivers
{
    public class ProfileDriver : ContentPartDriver<ProfilePart>
    {
        protected override DriverResult Display(ProfilePart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_Profile",
                () => shapeHelper.Parts_Profile(
                    FirstName: part.FirstName,
                    LastName: part.LastName));
        }

        protected override DriverResult Editor(ProfilePart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Profile_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Profile",
                    Model: part,
                    Prefix: Prefix));
        }

        protected override DriverResult Editor(ProfilePart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }

    }
}